<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of PaisDao
 *
 * @author UP23
 */
class UFDao extends BaseDao{


    public function get($id){

        $sql = " SELECT u.id, u.nome, ";
        $sql.= "        p.id, p.nome";
        $sql.= " FROM uf u INNER JOIN pais p ON (p.id = u.pais_id)";
        $sql.= " WHERE u.id = ?;";

        $stmt = $this->getPreparedStatment($sql);
        $stmt->bind_param('d', $id);
        $stmt->execute();

        $uf = new UF();
        $uf->setPais(new Pais());
        /*
         *  bind variables to prepared statement */
        $stmt->bind_result($ufId, $ufNome, $paisId, $paisNome);
        $stmt->fetch();

        $uf->setId($ufId);
        $uf->setNome($ufNome);
        $uf->getPais()->setId($paisId);
        $uf->getPais()->setNome($paisNome);

        $stmt->close();

        return $uf;
        
    }

    public function inserir($uf){
         $sql = "insert into uf (nome,pais_id) values(?,?);";

         $stmt = $this->getPreparedStatment($sql);
         $stmt->bind_param('sd', $uf->getNome(), $uf->getPais()->getId());
         $stmt->execute();
         $stmt->close();         
    }

    public function __destruct(){
         echo "<b><br/><br/>Rodei o destruct de UF!<br/><br/></b>";
         $this->fecharConexao();
    }
}
?>
